var bXmlHttpSupport = (typeof XMLHttpRequest != "undefined" || window.ActiveXObject);
     
    if (typeof XMLHttpRequest == "undefined" && window.ActiveXObject) {
        function XMLHttpRequest() {
            var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
                                 "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
                                 "Microsoft.XMLHTTP"];
                             
            for (var i=0; i <  arrSignatures.length; i++) {
                try {        
                    var oRequest = new ActiveXObject(arrSignatures[i]);            
                    return oRequest;        
                } catch (oError) { /*ignore*/ }
            }          
    
            throw new Error("MSXML is not installed on your system.");               
        }
    }    


function selectRow(id)
{
	var downframe = parent.frames["downFrame"];
	downframe.frames["downFramePage"].location="roleDetail.action?roleid="+id;
	downframe.frames["downFrameBar"].location="/ItsOAsystem/system/role/downFrameBar.jsp?roleid="+id;
}
function showDiv()
{
	var addWin = document.getElementById("addRoleWin");
	addWin.style.visibility = "visible";
}
function closeDiv()
{
	var addWin = document.getElementById("addRoleWin");
	addWin.style.visibility = "hidden";
}
function checkAll(checkbtn)
{
	var el = document.getElementsByTagName('input');
    var len = el.length;
    if(checkbtn.checked==true)
    {
    	for(var i=0; i<len; i++)
        {
            if(el[i].type=="checkbox")
            {
            	el[i].checked=true;
            }
        }
    	checkbtn.checked=true;
    }else
    {
    	for(var i=0; i<len; i++)
        {
            if(el[i].type=="checkbox")
            {
            	el[i].checked=false;
            }
        }
    	checkbtn.checked=false;
    }
}
/**
 * 跳转页面
 * @param pagename
 * @return
 */
function turnTo(pagename)
{
	var roleid = document.getElementById("roleid").value;
	if(roleid=="")
	{
		roleid = parent.frames["downFramePage"].document.getElementById("roleid").value;
		document.getElementById("roleid").value=roleid;
	}
	if(pagename=="roleDetail")
	{
		parent.frames["downFramePage"].location="roleDetail.action?roleid="+roleid;
	}else if(pagename=="pmsAssign")
	{
		parent.frames["downFramePage"].location="allPmsNopage.action?roleid="+roleid;
	}
}
/**
 * 更新按钮控制权限
 * @param btn
 * @param pmsid
 * @return
 */
function updateBtnCtrl(btn,pmsid)
{
	var btnCtrl = btn.value;
	var roleid = document.getElementById("roleid").value;
	var sUrl = "updatePmsRole.action?roleid="+roleid+"&pmsid="+pmsid+"&btnCtrl="+btnCtrl;
	if(bXmlHttpSupport) {
        var oRequest = new XMLHttpRequest();
        oRequest.open('POST', sUrl);
        oRequest.send(null);
    }
}
/**
 * checkbox 触发事件
 * @param chkstatus
 * @param chk
 * @return
 */
function checkChange(chk)
{
	var pmsid=chk.parentNode.parentNode.childNodes[1].childNodes[1].value;
	var roleid=document.getElementById("roleid").value;
	var url;
	if(chk.checked==false)
	{
		//取消选择
		chk.parentNode.parentNode.childNodes[11].childNodes[1].readOnly="readonly";
		url = "delPmsRole.action?pmsid="+pmsid+"&roleid="+roleid;
	}else
	{
		//选择
		chk.parentNode.parentNode.childNodes[11].childNodes[1].readOnly=false;
		url = "addPmsRole.action?pmsid="+pmsid+"&roleid="+roleid;
	}

	if(bXmlHttpSupport) {
        var sUrl = url;
        var oRequest = new XMLHttpRequest();
        oRequest.open('POST', sUrl);
        oRequest.send(null);
    }

}